package com.zy.openchat.core.model.user;

import android.os.Parcel;
import android.os.Parcelable;

import com.google.gson.annotations.SerializedName;
import com.ja.openchat.R;
import com.zy.openchat.App;
import com.zy.openchat.util.TimeUtils;

public class UserStatus implements Parcelable {

    //userStatusEmpty, userStatusLastMonth, userStatusLastWeek, userStatusOffline, userStatusOnline, and userStatusRecently.
    @SerializedName(value = "@type")
    public String type;

    //userStatusOffline
    public long was_online;

    //userStatusOnline
    public long expires;


    public String getLable(){
        if("userStatusLastMonth".equals(type)){
            return App.getInstanse().getString(R.string.online_a_month_ago);
        }else if("userStatusLastWeek".equals(type)){
            return App.getInstanse().getString(R.string.online_a_week_ago);
        }else if("userStatusOffline".equals(type)){
            if(was_online>0){
                return TimeUtils.onlineText(was_online*1000)+" "+App.getInstanse().getString(R.string.online_text);
            }
            return App.getInstanse().getString(R.string.offline_text);
        }else if("userStatusOnline".equals(type)){
            return App.getInstanse().getString(R.string.online_1_text);
        }else if("userStatusRecently".equals(type)){
            return App.getInstanse().getString(R.string.recently_online);
        }else{
            return "";
        }
    }


    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(this.type);
        dest.writeLong(this.was_online);
        dest.writeLong(this.expires);
    }

    public void readFromParcel(Parcel source) {
        this.type = source.readString();
        this.was_online = source.readLong();
        this.expires = source.readLong();
    }

    public UserStatus() {
    }

    protected UserStatus(Parcel in) {
        this.type = in.readString();
        this.was_online = in.readLong();
        this.expires = in.readLong();
    }

    public static final Creator<UserStatus> CREATOR = new Creator<UserStatus>() {
        @Override
        public UserStatus createFromParcel(Parcel source) {
            return new UserStatus(source);
        }

        @Override
        public UserStatus[] newArray(int size) {
            return new UserStatus[size];
        }
    };
}
